package com.test.auth_db_auto.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @Author: .Mr
 * @ClassName User
 * @Description TODO
 * @date 2021/11/30 16:22
 * @Version 1.0
 */
@Data
@Accessors(chain = true)
public class User implements Serializable, UserDetails {

    /*private int id;//用户Id
    private String username;//用户名称
    private String password;//用户密码
    private String phone;//手机号码
    private String email;//邮箱
    @TableField("last_login_time")
    private Date lastLoginTime;//最后一次登录时间

    @TableField(exist = false)
    private List<GrantedAuthority> authorities;*/
    @TableId(value = "id",type = IdType.AUTO)
    private String id;
    private String username;
    private String email;
    @TableField("isEnable")
    private Boolean isEnable;
    @TableField("isExpired")
    private Boolean isExpired;
    @TableField("isLocked")
    private Boolean isLocked;
    private String password;
    private String gender;
    private String mobile;

    @TableField(exist = false)
    private List<GrantedAuthority> authorities;

    @Override
    public List<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    /**
     * 用户账号是否过期
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 用户账号是否被锁定
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 用户密码是否过期
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 用户是否可用
     */
    @Override
    public boolean isEnabled() {
        return true;
    }
}
